Passed
Pull Request — master (#159)
by Mathieu
02:09
created

GetCooperativeQueryHandler.execute   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetCooperativeQuery } from './GetCooperativeQuery';
4
import { ICooperativeRepository } from 'src/Domain/Settings/Repository/ICooperativeRepository';
5
import { CooperativeNotFoundException } from 'src/Domain/Settings/Repository/CooperativeNotFoundException';
6
import { CooperativeView } from '../View/CooperativeView';
7
8
@QueryHandler(GetCooperativeQuery)
9
export class GetCooperativeQueryHandler {
10
  constructor(
11
    @Inject('ICooperativeRepository')
12
    private readonly cooperativeRepository: ICooperativeRepository
13
  ) {}
14
15
  public async execute(query: GetCooperativeQuery): Promise<CooperativeView> {
16
    const cooperative = await this.cooperativeRepository.find();
17
    if (!cooperative) {
18
      throw new CooperativeNotFoundException();
19
    }
20
21
    return new CooperativeView(cooperative.getDayDuration());
22
  }
23
}
24